package com.gdhengdian.collection._interface._impl;

import com.gdhengdian.collection._interface.Set;
import com.gdhengdian.tree_linkedList.LinkedList;

/**
 * @author HD-0078 杨炜耀
 * @date 2021-4-8 11:55
 */
public class LinkedListSet<E> implements Set<E> {

    private final LinkedList<E> linkedList;

    public LinkedListSet(){
        linkedList = new LinkedList<>();
    }

    @Override
    public void add(E e) {
        if(!linkedList.contains(e)){
            linkedList.addFirst(e);
        }
    }

    @Override
    public void remove(E e) {
        linkedList.removeElement(e);
    }

    @Override
    public boolean contains(E e) {
        return linkedList.contains(e);
    }

    @Override
    public int size() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }
}
